const chalk = require('chalk')
const redis = require('redis')
const config = require('config')
const { promisify } = require('util')
const trash = require('@/utils/ini.unit')
const redisOpts = [
  config.get('redis.port'),
  config.get('redis.host'),
  {
    auth_pass: trash.redispassword
  }
]
const client = redis.createClient(...redisOpts)
client.on('connect', function () {
  console.log(
    chalk.green('redis connect success')
  )
})

client.on('error', function (error) {
  console.log(
    chalk.red(error)
  )
})

exports.getAsync = promisify(client.get).bind(client)
exports.setAsync = promisify(client.set).bind(client)
exports.setexAsync = promisify(client.setex).bind(client)
exports.expireAsync = promisify(client.expire).bind(client)
exports.ttlAsync = promisify(client.ttl).bind(client)
exports.delAsync = promisify(client.del).bind(client)
